class Solution {
public:
    vector<int> findAnagrams(string s, string p) {
        vector<int>pcount(26);
        vector<int>scount(26);
        vector<int>v;
        int m = p.size();
        int n = s.size();

        if (n < m)
            return vector<int>();

        for (int i = 0; i < m; i++)
        {
            pcount[(p[i] - 'a')]++;
            scount[s[i] - 'a']++;
        }

        if (pcount == scount)
            v.emplace_back(0);

        for (int i = m; i < n; i++)
        {

            scount[s[i - m] - 'a']--;
            scount[s[i] - 'a']++;
            if (scount == pcount)
                v.emplace_back(i - 2);

        }
        return v;
    }
};